import { Controller, Get, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Public } from '~/modules/auth/decorators/public.decorator';
import { ApiTenantHeader } from '~/common/decorators/api-header-tenant.decorator';
import { ModuleSwaggerTags } from '~/constants/modules.constant';
import { AuthUser } from '~/modules/auth/decorators/auth-user.decorator';
import { CatalogService } from '~/modules/catalog/catalog.service';
import { CatalogEntity } from '~/modules/catalog/catalog.entity';

@ApiTags(ModuleSwaggerTags.CATALOG)
@ApiBearerAuth()
@Controller('catalog')
export class MiniappCatalogController {
	constructor(private readonly catalogService: CatalogService) {}

	@Public()
	@Get()
	@ApiTenantHeader()
	@ApiOperation({ summary: '获取分类列表' })
	async getCategories(@Query('categoryId') categoryId: string, @AuthUser() user: IAuthUser): Promise<CatalogEntity[]> {
		return await this.catalogService.findByCategoryId(Number(categoryId), user?.uid ?? null);
	}
}